#include "card.h"
Card::Card(unsigned int t,unsigned int n){
    if (t > 20) throw GameException("Wrong parameter: type of card not exist.");
    type = t;
    point = new unsigned int [2];
    switch (type) {
        case 0: //起始麦田
            color = blue;
            point[0] = 1;
            isBaseBuilding = true;
            cost = 0;
            name="麦田";
            no=n;
            break;
        case 1: //起始面包店
            color = green;
            point[0] = 2;
            point[1] = 3;
            isBaseBuilding = true;
            cost = 0;
            name="面包店";
            no=n;
            break;
        case 2: //游乐园
            color = golden;
            isLandmarkBuilding = true;
            cost = 16;
            name="游乐园";
            no=n;
            break;
        case 3: //广播塔
            color = golden;
            isLandmarkBuilding = true;
            cost = 22;
            name="广播塔";
            no=n;
            break;
        case 4: //购物中心
            color = golden;
            isLandmarkBuilding = true;
            cost = 10;
            name="购物中心";
            no=n;
            break;
        case 5: //火车站
            color = golden;
            isLandmarkBuilding = true;
            cost = 4;
            name="火车站";
            no=n;
            break;
        case 6: //商业中心
            color = purple;
            point[0] = 6;
            cost = 8;
            name="商业中心";
            no=n;
            break;
        case 7: //体育馆
            color = purple;
            point[0] = 6;
            cost = 6;
            name="体育馆";
            no=n;
            break;
        case 8: //电视台
            color = purple;
            point[0] = 6;
            cost = 7;
            name="电视台";
            no=n;
            break;
        case 9: //麦田
            color = blue;
            point[0] = 1;
            cost = 1;
            name="麦田";
            no=n;
            break;
        case 10:    //农场
            color = blue;
            point[0] = 2;
            cost = 1;
            name="农场";
            no=n;
            break;
        case 11:    //林场
            color = blue;
            point[0] = 5;
            cost = 3;
            name="林场";
            no=n;
            break;
        case 12:    //矿场
            color = blue;
            point[0] = 9;
            cost = 6;
            name="矿场";
            no=n;
            break;
        case 13:    //果园
            color = blue;
            point[0] = 10;
            cost = 3;
            name="果园";
            no=n;
            break;
        case 14:    //咖啡馆
            color = red;
            point[0] = 3;
            cost = 2;
            name="咖啡馆";
            no=n;
            break;
        case 15:    //西餐厅
            color = red;
            point[0] = 9;
            point[1] = 10;
            cost = 3;
            name="西餐厅";
            no=n;
            break;
        case 16:    //面包店
            color = green;
            point[0] = 2;
            point[1] = 3;
            cost = 1;
            name="面包店";
            no=n;
            break;
        case 17:    //便利店
            color = green;
            point[0] = 4;
            cost = 2;
            name="便利店";
            no=n;
            break;
        case 18:    //奶酪工厂
            color = green;
            point[0] = 7;
            cost = 5;
            name="奶酪工厂";
            no=n;
            break;
        case 19:    //家具工厂
            color = green;
            point[0] = 8;
            cost = 3;
            name="家具工厂";
            no=n;
            break;
        case 20:    //蔬菜超市
            color = green;
            point[0] = 11;
            point[1] = 12;
            cost = 2;
            name="蔬菜超市";
            no=n;
            break;
    }
}

const bool Card::isTriggeringTheCard(unsigned int p) const {
    if (point[0] == p || point[1] == p) return true;
    return false;
}

string Card::toString() {
    string s = "";
    s += name;
    s += "(";
    s += to_string(cost);
    s += ")";
    return s;
}

CardsTab* CardsTab::instance = nullptr;

CardsTab::CardsTab() {
    unsigned int k = 0;
    for (int i = 0; i < 9; i++) {    //创建type 0~8的牌各四张
        for (int j = 0; j < 4; j++) {
            const Card* card = new const Card(i, k);
            cards.push_back(const_cast<Card*>(card));
            k++;
        }
    }
    for (int i = 9; i < 21; i++) {  //创建type 9~20的牌各六张
        for (int j = 0; j < 6; j++) {
            const Card* card = new const Card(i, k);
            cards.push_back(const_cast<Card*>(card));
            k++;
        }
    }
}

CardsTab::~CardsTab() {
    for (size_t i = 0; i < totalNumOfCards; i++)
        delete cards[i];
}
